package com.example.mediademo.opengl;

import android.content.Context;
import android.graphics.PointF;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

public class DefGlSurfaceView extends GLSurfaceView {

    private PointF mPrePoint = new PointF();

    private VideoDrawer mDrawer = null;

    public DefGlSurfaceView(Context context) {
        super(context);
    }

    public DefGlSurfaceView(Context context, AttributeSet attributeSet) {
        super(context,attributeSet);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mPrePoint.x = event.getX();
                mPrePoint.y = event.getY();
                Log.d("baiaj1","onTouch:x " + mPrePoint.x + " y:" + mPrePoint.y);
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d("baiaj1","onTouch:getWidth " + getWidth() + " getHeight:" + getHeight());
                float dx = (event.getX() - mPrePoint.x) / getWidth();
                float dy = (event.getY() - mPrePoint.y) / getHeight();

                if (mDrawer != null) {
                    mDrawer.translate(dx,dy);
                }
                mPrePoint.x = event.getX();
                mPrePoint.y = event.getY();
                Log.d("baiaj1","onTouch:x " + mPrePoint.x + " y:" + mPrePoint.y);
                break;
            default:
                break;
        }
        return true;
    }

    public void addDrawer(VideoDrawer drawder) {
        mDrawer = drawder;
    }
}
